package org.apm.data.check;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apm.data.pusher.CommonMethod;
import org.elasticsearch.action.bulk.BulkProcessor;
import org.elasticsearch.client.Client;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

import com.alibaba.fastjson.JSONObject;

public class EventDataReIndex extends DataReIndex {
    private static final Logger LOGGER = LogManager.getLogger(EventDataReIndex.class);
    private static final String TYPE = "Event";

    public EventDataReIndex() {}

    public EventDataReIndex(Client client, BulkProcessor esBulkProcessor) {
        super(client, esBulkProcessor);
    }

    @Override
    protected boolean checkIndex(String index) {
        return index.contains(TYPE.toLowerCase());
    }

    @Override
    protected QueryBuilder query() {
        return QueryBuilders.boolQuery()
                .filter(QueryBuilders.termQuery("baseUrl", "/public/hzbank/hzbankPriorRePayNotifyForP2P.html"));
    }

    @Override
    protected DataBean processData(String dataSource) {
        try {
            return new DataBean(dataSource);
        } catch (Exception exception) {
            LOGGER.error(exception.getMessage());
            exception.printStackTrace();
        }
        return new DataBean();
    }

    public static void main(String[] args) {
        System.out.println(CommonMethod.onlineClient().prepareSearch("apm2.0-183.129.153.146-event-back")
                .setQuery(QueryBuilders.boolQuery()
                        .filter(QueryBuilders.termQuery("baseUrl", "/public/hzbank/hzbankPriorRePayNotifyForP2P.html")))
                .execute().actionGet());
    }

}
